package Swing;

import javax.swing.*;
import java.awt.*;

public class Demo95 {
    public static void main (String[] args) {
        JFrame jf=new JFrame ("text");
        jf.setBounds (200,200,500,500);
        jf.setResizable (true);
        jf.setDefaultCloseOperation (WindowConstants.EXIT_ON_CLOSE);
        Container pane = jf.getContentPane ();
        JPanel jp=new JPanel ();
        //*****************************************************************
        JList<String> all=new JList<> (new String[]{"red","green","cyan"});
        all.setPreferredSize (new Dimension (100,60));
        all.setForeground (Color.black);
        all.setSelectedIndex (0);
        all.setSelectionBackground (new Color (255,200,220,100));
        JSlider js=new JSlider ();
        js.setMinimum (0);
        js.setMaximum (100);
        js.setPreferredSize (new Dimension (200,20));
        int value = js.getValue ();
        all.addListSelectionListener ((event)->{
            if (all.isSelectedIndex (0)){
                jp.setBackground (new Color (255,0,0,value));
            }
            if (all.isSelectedIndex (1)){
                jp.setBackground (Color.green);
            }
            if (all.isSelectedIndex (2)){
                jp.setBackground (Color.cyan);
            }

        });
        jp.add (js);
        jp.add (all);

        //*****************************************************************
        pane.add (jp);
        jf.setVisible (true);
    }
}

